package cn.com.header.zbpk.base.service.impl;

import cn.com.header.zbpk.base.entity.Subject;
import cn.com.header.zbpk.base.mapper.ISubjectMapper;
import cn.com.header.zbpk.base.service.ISubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

/**
 * @author Yuanyifeng
 * @date 2017-11-21
 * @time 17:39
 */
@Service
public class SubjectServiceImpl implements ISubjectService {
    @Autowired
    private ISubjectMapper iSubjectMapper;

    @Override
    public List<Subject> loads(Subject subject, boolean nameLikeMode, Set<String> fields) {
        return iSubjectMapper.loads(subject, nameLikeMode, fields);
    }

    @Override
    public Optional<Subject> loadBy(Long id, Set<String> fields) {
        Subject subject = new Subject(id);
        List<Subject> subjects = iSubjectMapper.loads(subject, false, fields);
        if (Objects.isNull(subjects) && subjects.isEmpty()){
            return Optional.empty();
        }
        return Optional.of(subjects.get(0));
    }
}
